package com.zhou.bjgl.bjgl.business_web.controller;


import com.zhou.bjgl.bjgl.exception.BwExceptionEnum;
import com.zhou.bjgl.bjgl.myAnnotations.UserLoginToken;
import com.zhou.bjgl.bjgl.req.b_class.BClassAddReq;
import com.zhou.bjgl.bjgl.req.b_class.BClassQueryReq;
import com.zhou.bjgl.bjgl.resp.BClassResp;
import com.zhou.bjgl.bjgl.resp.PageResp;
import com.zhou.bjgl.bjgl.resp.common.ApiRestResponse;
import com.zhou.bjgl.bjgl.business_web.service.BClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 班级管理
 * </p>
 *
 * @author jz
 * @since 2021-07-04
 */
@RestController
@RequestMapping("/bjgl/class")
@Api("班级管理")
public class BClassController {

    @Resource
    private BClassService bClassService;

    @ApiOperation("添加或修改班级")
    @PostMapping("/add")
    @UserLoginToken
    public ApiRestResponse add(@RequestBody BClassAddReq req) {
        bClassService.add(req);
        return ApiRestResponse.success();
    }

    @ApiOperation("班级列表")
    @GetMapping("/list")
    @UserLoginToken
    public ApiRestResponse list(BClassQueryReq req) {
        PageResp<BClassResp> collegeListResp=bClassService.listClass(req);
        return ApiRestResponse.success(collegeListResp);
    }

    @ApiOperation("删除班级")
    @PostMapping("/delete")
    @UserLoginToken
    public ApiRestResponse delete(@RequestBody BClassQueryReq req) {
        boolean removeById = bClassService.removeById(req.getId());
        if (removeById == false) {
            return ApiRestResponse.error(BwExceptionEnum.DELETE_FAILID);
        }
        return ApiRestResponse.success();
    }
}

